package xddq

import (
	"fmt"
	D "websocket_apn/define"
	"websocket_apn/log"
	"websocket_apn/proto"
)

//地图数据
var GodIslandAddMapData = map[int]D.GodIslandAddMapInfo{
	1001: {Level: 1, Name: "基地-上", Link: []int{2002, 2003}},
	1002: {Level: 1, Name: "基地-右上", Link: []int{2022, 2023}},
	1003: {Level: 1, Name: "基地-左下", Link: []int{2010, 2011}},
	1004: {Level: 1, Name: "基地-下左", Link: []int{2012, 2013}},
	1005: {Level: 1, Name: "基地-下", Link: []int{2014, 2015}},
	1006: {Level: 1, Name: "基地-上右", Link: []int{2001, 2024}},
	1007: {Level: 1, Name: "基地-左", Link: []int{2008, 2009}},
	1008: {Level: 1, Name: "基地-上左", Link: []int{2004, 2005}},
	1009: {Level: 1, Name: "基地-左上", Link: []int{2006, 2007}},
	1010: {Level: 1, Name: "基地-右", Link: []int{2020, 2021}},
	1011: {Level: 1, Name: "基地-右下", Link: []int{2018, 2019}},
	1012: {Level: 1, Name: "基地-下右", Link: []int{2016, 2017}},
	2001: {Level: 2, Name: "金华灵脉", Link: []int{1006, 2002, 2024, 4001}},
	2002: {Level: 2, Name: "桃山灵脉", Link: []int{1001, 2001, 2003, 4001}},
	2003: {Level: 2, Name: "天目灵脉", Link: []int{1001, 2002, 2004, 4001}},
	2004: {Level: 2, Name: "紫盖灵脉", Link: []int{1008, 2003, 2005, 4001}},
	2005: {Level: 2, Name: "良常灵脉", Link: []int{1008, 2004, 2006, 3004}},
	2006: {Level: 2, Name: "若水灵脉", Link: []int{1009, 2005, 2007, 3004}},
	2007: {Level: 2, Name: "青田灵脉", Link: []int{1009, 2006, 2008, 4003}},
	2008: {Level: 2, Name: "金庭灵脉", Link: []int{1007, 2007, 2009, 4003}},
	2009: {Level: 2, Name: "大有灵脉", Link: []int{1007, 2008, 2010, 4003}},
	2010: {Level: 2, Name: "洞阳灵脉", Link: []int{1003, 2009, 2011, 4003}},
	2011: {Level: 2, Name: "寻罗灵脉", Link: []int{1003, 2010, 2012, 3003}},
	2012: {Level: 2, Name: "白石灵脉", Link: []int{1004, 2011, 2013, 3003}},
	2013: {Level: 2, Name: "都乔灵脉", Link: []int{1004, 2012, 2014, 4002}},
	2014: {Level: 2, Name: "紫竹灵脉", Link: []int{1005, 2013, 2015, 4002}},
	2015: {Level: 2, Name: "华盖灵脉", Link: []int{1005, 2014, 2016, 4002}},
	2016: {Level: 2, Name: "华清灵脉", Link: []int{1012, 2015, 2017, 4002}},
	2017: {Level: 2, Name: "玉循灵脉", Link: []int{1012, 2016, 2018, 3002}},
	2018: {Level: 2, Name: "常水灵脉", Link: []int{1011, 2017, 2019, 3002}},
	2019: {Level: 2, Name: "清与灵脉", Link: []int{1011, 2018, 2020, 4004}},
	2020: {Level: 2, Name: "玉留灵脉", Link: []int{1010, 2019, 2021, 4004}},
	2021: {Level: 2, Name: "清远灵脉", Link: []int{1010, 2020, 2022, 4004}},
	2022: {Level: 2, Name: "商谷灵脉", Link: []int{1002, 2021, 2023, 4004}},
	2023: {Level: 2, Name: "抱福灵脉", Link: []int{1002, 2022, 2024, 3001}},
	2024: {Level: 2, Name: "漳龙灵脉", Link: []int{1006, 2001, 2023, 3001}},
	2025: {Level: 2, Name: "青月灵脉", Link: []int{3001, 4004, 5001}},
	2026: {Level: 2, Name: "玉虚灵脉", Link: []int{3004, 4001, 5001}},
	2027: {Level: 2, Name: "苍山灵脉", Link: []int{3003, 4003, 5001}},
	2028: {Level: 2, Name: "冰玄灵脉", Link: []int{3002, 4002, 5001}},
	3001: {Level: 3, Name: "定阳灵脉", Link: []int{2023, 2024, 2025}},
	3002: {Level: 3, Name: "无妄灵脉", Link: []int{2017, 2018, 2028}},
	3003: {Level: 3, Name: "长留灵脉", Link: []int{2011, 2012, 2027}},
	3004: {Level: 3, Name: "三危灵脉", Link: []int{2005, 2006, 2026}},
	4001: {Level: 4, Name: "圣源灵脉", Link: []int{2001, 2002, 2003, 2004, 2026}},
	4002: {Level: 4, Name: "南洲灵脉", Link: []int{2013, 2014, 2015, 2016, 2028}},
	4003: {Level: 4, Name: "西洲灵脉", Link: []int{2007, 2008, 2009, 2010, 2027}},
	4004: {Level: 4, Name: "东洲灵脉", Link: []int{2019, 2020, 2021, 2022, 2025}},
	5001: {Level: 5, Name: "九仙灵脉", Link: []int{2025, 2026, 2027, 2028}},
	6001: {Level: 6, Name: "修罗城", Link: []int{}},
}

//蓬莱仙岛-处理灵气状态
func (xd *XdDriver) CheckGodIslandSpiInfoData(info D.GodIslandSpiInfo) {
	xd.UserData.GodIslandInfo.Spi = info
	if info.Save > 0 && info.SpiLimit-info.Spi > 0 {
		addSpi := info.SpiLimit - info.Spi
		if addSpi > info.Save {
			addSpi = info.Save
		}
		log.Infof("蓬莱仙岛-开始恢复%d灵力", addSpi)
		xd.Send(proto.Get_Cmd_Data(xd.userInfo.PlayerId, proto.S_GOD_ISLAND_GAME_USE_SPIRITUALBALL, fmt.Sprintf("08 %s 10 %s",
			xd.UserData.Activity[D.Activity_GOD_ISLAND_GAME_PLANT].ID, proto.HexToHexStr(proto.IntDataToBytes(addSpi)))))
	}
}

//蓬莱仙岛-处理地图信息
func (xd *XdDriver) CheckGodIslandMapInfoData(info D.GodIslandMapInfo) {
	xd.UserData.GodIslandInfo.MapD = GodIslandAddMapData
	for idx, _ := range info.Add {
		mapD := xd.UserData.GodIslandInfo.MapD[info.Add[idx].PlaceId]
		if info.Add[idx].PlaceId < 1500 {
			//是否是大本营
			if info.Add[idx].YmID == xd.UserData.YaoMengID {
				info.Add[idx].IsOccupy = true
				mapD.IsStart = true
				xd.UserData.GodIslandInfo.SelfPlaceID = info.Add[idx].PlaceId
			} else {
				mapD.IsStart = false
			}
		} else {
			if info.Add[idx].YmID == xd.UserData.YaoMengID {
				info.Add[idx].IsOccupy = true
				mapD.IsOS = true
			} else if len(info.Add[idx].YmID) > 0 {
				mapD.IsOE = true
			} else {
				mapD.IsOS = false
				mapD.IsOE = false
			}
		}
		xd.UserData.GodIslandInfo.MapD[info.Add[idx].PlaceId] = mapD
		log.Infof("%+v", mapD)
	}
	xd.UserData.GodIslandInfo.Map = info
}

/*
使用蓬莱仙果
[DEBUG] [2024/09/25 20:28:16] [PRJ/websocket_apn/main_test.go]:[  193]:   ↑↑↑↑↑ S_GOD_ISLAND_GAME_USE_FRUIT - len:25
[DEBUG] [2024/09/25 20:28:16] [PRJ/websocket_apn/main_test.go]:[  200]:   PayloadBytes: 71 AB 00 00 00 19 00 03 27 F5 00 00 02D4 07 01 81 E2 08 E2 B7 E5 04 10 09
[DEBUG] [2024/09/25 20:28:16] [PRJ/websocket_apn/main_test.go]:[  195]:   ↓↓↓↓↓ game cmd[6837]-unkown - len:45
[DEBUG] [2024/09/25 20:28:16] [PRJ/websocket_apn/main_test.go]:[  200]:   PayloadBytes: 71 AB 00 00 00 2D 00 00 1A B5 00 00 02D4 07 01 81 E2 08 00 12 08 31 30 35 30 33 39 3D 39 1A 05 39 36 39 38 35 22 06 34 39 33 33 31 30
[DEBUG] [2024/09/25 20:28:16] [PRJ/websocket_apn/main_test.go]:[  203]:   	>>> 1 - code 08[8] len:0-_
[DEBUG] [2024/09/25 20:28:16] [PRJ/websocket_apn/main_test.go]:[  203]:   	>>> 2 - code 12[18] len:8-31 30 35 30 33 39 3D 39_
105039=9
[DEBUG] [2024/09/25 20:28:16] [PRJ/websocket_apn/main_test.go]:[  203]:   	>>> 3 - code 1A[26] len:5-39 36 39 38 35_
96985
*/

/*
90 4E是分组
[DEBUG] [2024/10/21 20:54:30] [PRJ/websocket_apn/main_test.go]:[  193]:   ↑↑↑↑↑ S_GOD_ISLAND_BASE_INFO_LOAD - len:23
[DEBUG] [2024/10/21 20:54:30] [PRJ/websocket_apn/main_test.go]:[  200]:   PayloadBytes: 71 AB 00 00 00 17 00 03 27 D1 00 00 02 D4 07 01 81 E2 08 FA C5 EB 04
[DEBUG] [2024/10/21 20:54:30] [PRJ/websocket_apn/main_test.go]:[  195]:   ↓↓↓↓↓ S_GOD_ISLAND_BASE_INFO_LOAD_RSP - len:61
[DEBUG] [2024/10/21 20:54:30] [PRJ/websocket_apn/main_test.go]:[  200]:   PayloadBytes: 71 AB 00 00 00 3D 00 00 1A 91 00 00 02 D4 07 01 81 E2 08 00 10 FA C5 EB 04 18 01 20 01 28 90 4E 30 9B A2 8B EC 73 38 034A 05 08 90 4E 10 06 4A 05 08 91 4E 10 00 4A 05 08 92 4E 10 00

[DEBUG] [2024/10/21 20:47:25] [PRJ/websocket_apn/main_test.go]:[  193]:   ↑↑↑↑↑ S_GOD_ISLAND_GAME_INFO_LOAD - len:23
[DEBUG] [2024/10/21 20:47:25] [PRJ/websocket_apn/main_test.go]:[  200]:   PayloadBytes: 71 AB 00 00 00 17 00 03 27 E4 00 00 02D4 07 01 81 E2 08 FA C5 EB 04
[DEBUG] [2024/10/21 20:47:25] [PRJ/websocket_apn/main_test.go]:[  195]:   ↓↓↓↓↓ S_GOD_ISLAND_GAME_INFO_LOAD_RSP - len:296
[DEBUG] [2024/10/21 20:47:25] [PRJ/websocket_apn/main_test.go]:[  200]:   PayloadBytes: 71 AB 00 00 01 28 00 00 1A A4 00 00 02D4 07 01 81 E2 08 00 10 E9 07 32 37 08 D1 0F 10 D1 0F 1A 0F E2 98 95 EF B8 8F E9 9B A8 E8 BD A9 E9 98 81 20 80 DA 93 F4 AA 32 28 80 CE 82 FB AA 32 30 D3 C6 DC F0 AA 32 38 AB E6 BD 01 40 9B A2 8B EC 73 32 37 08 D3 0F 10 D3 0F 1A 0F E2 98 95EF B8 8F E9 9B A8 E8 BD A9 E9 98 81 20 80 DA 93 F4 AA 32 28 80 CE 82 FB AA 32 30 D3 C6 DC F0 AA 32 38 AB E6 BD 01 40 9B A2 8B EC 73 32 37 08 A4 1F 10 D2 0F 1A 0F E2 98 95 EF B8 8F E9 9B A8 E8 BD A9 E9 98 81 20 80 DA 93 F4 AA 32 28 80 CE 82FB AA 32 30 D3 C6 DC F0 AA 32 38 AB E6 BD 01 40 9B A2 8B EC 73 32 37 08 D8 0F 10 D4 0F 1A 0F E2 98 95 EF B8 8F E9 9B A8 E8 BD A9 E9 98 81 20 80 DA 93 F4 AA 32 28 80 CE 82 FB AA 32 30 D3 C6 DC F0 AA 32 38 AB E6 BD 01 40 9B A2 8B EC 73 40 0058 00 62 01 30 6A 06 31 31 30 32 39 39 70 00 78 88 B6 88 F8 AA 32 80 01 00 88 01 00 9A 01 0C 08 01 10 C8 01 18 98 FB 8B F8 AA 32

[DEBUG] [2024/10/21 20:56:39] [PRJ/websocket_apn/main_test.go]:[  193]:   ↑↑↑↑↑ S_GOD_ISLAND_GAME_MINIMAP_INFO - len:28
[DEBUG] [2024/10/21 20:56:39] [PRJ/websocket_apn/main_test.go]:[  200]:   PayloadBytes: 71 AB 00 00 00 1C 00 03 27 F2 00 00 02D4 07 01 81 E2 08 FA C5 EB 04 10 90 4E 18 01
*/
